/**
 * 
 */
package edu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.dao.BaseDao;
import edu.entity.Attachment;
import edu.entity.ModuleData;

/**
 * @author yanshichuan
 * 2013年9月1日 下午10:12:56
 */
@Service("attachmentService")
public class AttachmentService extends BaseService {
	@Autowired
	private BaseDao baseDao;
	public void insertAttachment(Attachment attachment) throws Exception {
		if(attachment!=null){
			baseDao.insert(attachment);
		}
	}
	
	public void updateAttachment(Attachment attachment) throws Exception {
		if(attachment!=null){
			baseDao.update(attachment);
		}
	}
	
	public void deleteAttachment(Attachment attachment) throws Exception {
		if(attachment!=null){
			baseDao.delete(attachment);
		}
	}
	 public void deleteAttachmentById(String id) throws Exception {
		 if(id!=null){
	    	this.baseDao.deleteById(Attachment.class, id);
		 }
	  }
	public void deleteAttachmentByModuleData(ModuleData moduleData) throws Exception {
		if(moduleData!=null){
			baseDao.batchDeleteByHql("delete from Attachment a where a.moduleData.id='"+moduleData.getId()+"'");
		}
	}
	
	public Attachment selectAttachmentById(String id) throws Exception {
		Attachment attachment=null;
		if(id!=null){
			attachment=(Attachment) baseDao.selectObjById(Attachment.class, id);
		}
		return attachment;
	}
	
	public List<Attachment> selectAttachmentsByModuleData(ModuleData moduleData) throws Exception{
		List<Attachment> list=null;
		if(moduleData!=null){
			list=baseDao.selectPojoByHql("from Attachment a where a.moduleData.id='"+moduleData.getId()+"'");
		}
		return list;
	}
}
